package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.board.PlayingDeck;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.exception.CastException;
import com.wimcorp.magic.input.Location;

/**
 * example {target: 'SELF',scry : 2}
 * 
 * target options : SELF
 * 
 * 
 * scry : 1,2,3
 */
@Entity
@Table(name = "scry", schema = "abilities")
public class Scry extends Ability {
	
	private int scry;

	protected Scry() {
	}

	public Scry(AbilityTrigger trigger) {
		super(trigger);
	}
	
	public Scry(Scry ability) {
		super(ability);
		this.scry = ability.getScry();
	}


	public void cast() throws Exception {
		PlayingDeck deck = getPlayer().getDeck();
		getPlayer().getUserInterface().message(getDescription());
		for (int i = 0; i < scry; i++) {
			PlayingCard card = deck.reveal(i);
			getPlayer().getUserInterface().message(card.toString());
			boolean input = getPlayer().getUserInterface().selectBoolean(
					"Would you like to place " + card.getName() + " on the bottom of your library?");
			if (input) {
				deck.addOnBottom(deck.getTopCard());
			}
		}
	}


	@Override
	protected void executeAbility() throws CastException {

	}

	public int getScry() {
		return scry;
	}

	@Override
	public Scry clone() {
		return new Scry(this);
	}

	public void setScry(int scry) {
		this.scry = scry;
	}
	
	
	
	

}
